home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1035 / 1035.xpi / chrome / 1clickweather.jar / content / 1clickweather / js / data / lifestyle.js < prev    next >
Text File  |  2008-10-05  |  4KB  |  122 lines

  1. // ⌐ 2005 The Weather Channel Interactive, Inc.  All Rights Reserved.
  2.  
  3. var XULSimple = null;
  4. var GlobalLifeStyle = null;
  5.  
  6. function enableDebug() {
  7.    Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService).notifyObservers(null, "debugupdate", null);
  8.    window.close();
  9. }
  10.  
  11. function loadLifestyle(){
  12.    try{
  13.       jsInclude("chrome://1clickweather/content/js/utils/definitions.js");
  14.       jsInclude("chrome://1clickweather/content/js/utils/xul.js");
  15.       jsInclude("chrome://1clickweather/content/js/utils/datadumper.js");
  16.       jsInclude("chrome://1clickweather/content/js/utils/appconstants.js");
  17.  
  18.       try{
  19.          // fire up the config system.
  20.          // loadconfig.js can be included where ever you need access to config variables.
  21.          // it will pop GlobalUserConfig and GlobalAppConfig into existance
  22.          jsInclude("chrome://1clickweather/content/js/config/loadconfig.js");
  23.       }catch(e){
  24.          debug("lifestyle loadconfig: " + e);
  25.       }
  26.  
  27.       XULSimple = new oXULSimple;
  28.  
  29.       GlobalLifeStyle = new oLifestyle();
  30.       GlobalLifeStyle.Top();
  31.       GlobalLifeStyle.Middle();
  32. //      document.getElementById("LifeStyleWindow").setAttribute("title", "1-ClickWeather");
  33.    }catch(e){
  34.       debug("lifestyle init: " + e);
  35.    }
  36. }
  37.  
  38. // this doesn't really need to be an object but being so,
  39. // methods and variables are automatically scoped properly
  40. // so we don't step on other things
  41. function oLifestyle(){
  42.  
  43.    this.Top = function(){
  44.       var top = document.getElementById("lifestyleTopLeft");
  45.       var Vbox = document.createElement("vbox");
  46.       top.appendChild(Vbox);
  47.  
  48.       this.drawLink(Vbox, 'homepage');
  49.       XULSimple.Shim(Vbox, 8, 8);
  50.       this.drawLink(Vbox, '36hour');
  51.       XULSimple.Shim(Vbox, 8, 8);
  52.       this.drawLink(Vbox, '10day');
  53.  
  54.       var top = document.getElementById("lifestyleTopRight");
  55.       var Vbox = document.createElement("vbox");
  56.       top.appendChild(Vbox);
  57.  
  58.       XULSimple.Shim(Vbox, 6, 6);
  59.       this.drawLink(Vbox, 'desktop');
  60.    }
  61.  
  62.    this.Middle = function(){
  63.       var middle = document.getElementById("lifestyleMiddleLeft");
  64.       var links = hash2array(GlobalUserConfig.getAllProfiles().getDefaultProfile().getLifeStyle().getLinks());
  65.  
  66.       // figure out how many links should show in the left hand vbox
  67.       var maxrow = links.length / 2;
  68.       if((maxrow * 2) < links.length){
  69.          maxrow++;
  70.       }
  71.  
  72.       var counter = 0;
  73.       for(var i in links){
  74.          if(counter >= maxrow){
  75.             counter = 0;
  76.             var middle = document.getElementById("lifestyleMiddleRight");
  77.          }
  78.  
  79.          this.drawLink(middle, links[i]);
  80.          XULSimple.Shim(middle, 8, 8);
  81.  
  82.          counter++;
  83.       }
  84.    }
  85.  
  86.    this.drawLink = function(box, index, args){
  87.       var linkUrl = GlobalAppConfig.getLinkByID(index).getURL();
  88.       linkUrl = linkUrl.replace(/LOCIDTAG/g, GlobalUserConfig.getAllProfiles().getDefaultProfile().getSetup().getLocation().getLocID());
  89.  
  90.       var Hbox = document.createElement("hbox");
  91.       box.appendChild(Hbox);
  92.  
  93.       var icon = new oXUL.iconByID(Hbox, GlobalAppConfig.getLinkByID(index).getIcon());
  94.       icon.onClick('GlobalLifeStyle.openLink("' + linkUrl + '");');
  95.       icon.Make();
  96.  
  97.       var label = new oXUL.Label(Hbox, GlobalAppConfig.getLinkByID(index).getText());
  98.       label.setAttribute("class", "text-link");
  99.       label.onClick('GlobalLifeStyle.openLink("' + linkUrl + '");');
  100.       label.Make();
  101.    }
  102.  
  103.  
  104.    this.openLink = function(url){
  105.       if(url){
  106.          try{
  107.             // get ahold of the main browser window so we can load a url in it
  108.             openLinkInNewTab(url);
  109.             //var b = getBrowserWindow();
  110.             //b.loadURI(url);
  111.             // and close the lifestyle window
  112.             window.close();
  113.          }catch(e){
  114.             debug("error lifestyle open link: " + e);
  115.          }
  116.       }
  117.    }
  118. }
  119.  
  120.  
  121.  
  122.